import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

# 向La和Lb每次都从最后插
# x=(1,2,3,4,5,6,7)
# y1=[0.095, 0.407,275.103, 0, 0.111, 0.626, 0.029]
# y2=[0.021,443.532, 682.775, 0.252, 353.857, 1233.06, 0.391]

# sum_y1 = 0
# sum_y2 = 0
# for i in range(7):
#     sum_y1 += y1[i]
#     y1[i] = sum_y1
#     sum_y2 += y2[i]
#     y2[i] = sum_y2
# plt.plot(x,y1,'r--',x,y2,'g--',marker='*') # 此时x不可省略
# plt.xlabel('step')
# plt.ylabel('elspsed time (ms)')
# plt.legend(["SqList","LinkList"],loc='upper left')
# plt.title("n=10000  SqList and LinkList elspsed time algo2.1 and algo 2.2")
# plt.show()

# 向La和Lb每次都从头插
x=(1,2,3,4,5,6,7)
y1=[0.146, 1625.95,819.013, 0, 952.942, 0.859, 0.051]
y2=[0.177,1.691,1376.94, 0.275, 0.462, 2167.32, 0.578]

sum_y1 = 0
sum_y2 = 0
for i in range(7):
    sum_y1 += y1[i]
    y1[i] = sum_y1
    sum_y2 += y2[i]
    y2[i] = sum_y2
plt.plot(x,y1,'r--',x,y2,'g--',marker='*') # 此时x不可省略
plt.xlabel('step')
plt.ylabel('elspsed time (ms)')
plt.legend(["SqList","LinkList"],loc='upper left')
plt.title("n=10000  SqList and LinkList elspsed time algo2.1 and algo 2.2")
plt.show()